home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / kermit / ckuusr.c < prev    next >
C/C++ Source or Header  |  1990-07-19  |  34KB  |  1,229 lines

  1. char *userv = "User Interface 4E(059), 29 Jan 88";
  2.  
  3. /*  C K U U S R --  "User Interface" for Unix Kermit (Part 1)  */
  4.  
  5. /*
  6.  4E, support for Apollo Aegis, Data General added, July 87.
  7. */
  8. /*
  9.  Author: Frank da Cruz (SY.FDC@CU20B),
  10.  Columbia University Center for Computing Activities, January 1985.
  11.  Copyright (C) 1985, Trustees of Columbia University in the City of New York.
  12.  Permission is granted to any individual or institution to use, copy, or
  13.  redistribute this software so long as it is not sold for profit, provided this
  14.  copyright notice is retained. 
  15. */
  16.  
  17. /*
  18.  The ckuusr module contains the terminal input and output functions for Unix
  19.  Kermit.  It includes a simple Unix-style command line parser as well as
  20.  an interactive prompting keyword command parser.  It depends on the existence
  21.  of Unix facilities like fopen, fgets, feof, (f)printf, argv/argc, etc.  Other
  22.  functions that are likely to vary among Unix implementations -- like setting
  23.  terminal modes or interrupts -- are invoked via calls to functions that are
  24.  defined in the system-dependent modules, ck?[ft]io.c.
  25.  
  26.  The command line parser processes any arguments found on the command line,
  27.  as passed to main() via argv/argc.  The interactive parser uses the facilities
  28.  of the cmd package (developed for this program, but usable by any program).
  29.  
  30.  Any command parser may be substituted for this one.  The only requirements
  31.  for the Kermit command parser are these:
  32.  
  33.  1. Set parameters via global variables like duplex, speed, ttname, etc.
  34.     See ckmain.c for the declarations and descriptions of these variables.
  35.  
  36.  2. If a command can be executed without the use of Kermit protocol, then
  37.     execute the command directly and set the variable sstate to 0. Examples
  38.     include 'set' commands, local directory listings, the 'connect' command.
  39.  
  40.  3. If a command requires the Kermit protocol, set the following variables:
  41.  
  42.     sstate                             string data
  43.       'x' (enter server mode)            (none)
  44.       'r' (send a 'get' command)         cmarg, cmarg2
  45.       'v' (enter receive mode)           cmarg2
  46.       'g' (send a generic command)       cmarg
  47.       's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  48.       'c' (send a remote host command)   cmarg
  49.  
  50.     cmlist is an array of pointers to strings.
  51.     cmarg, cmarg2 are pointers to strings.
  52.     nfils is an integer.    
  53.  
  54.     cmarg can be a filename string (possibly wild), or
  55.        a pointer to a prefabricated generic command string, or
  56.        a pointer to a host command string.
  57.     cmarg2 is the name to send a single file under, or
  58.        the name under which to store an incoming file; must not be wild.
  59.     cmlist is a list of nonwild filenames, such as passed via argv.
  60.     nfils is an integer, interpreted as follows:
  61.       -1: argument string is in cmarg, and should be expanded internally.
  62.        0: stdin.
  63.       >0: number of files to send, from cmlist.
  64.  
  65.  The screen() function is used to update the screen during file transfer.
  66.  The tlog() function maintains a transaction log.
  67.  The debug() function maintains a debugging log.
  68.  The intmsg() and chkint() functions provide the user i/o for interrupting
  69.    file transfers.
  70. */
  71.  
  72. /* Includes */
  73.  
  74. #include "ckcdeb.h"
  75. #include <stdio.h>
  76. #include <ctype.h>
  77. #ifndef AMIGA
  78. #include <signal.h>
  79. #endif
  80. #include "ckcker.h"
  81. #include "ckucmd.h"
  82. #include "ckuusr.h"
  83.  
  84. #ifdef datageneral
  85. #define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd) 
  86. #define fork() vfork()
  87. /* DG version 3.21 of C has bugs in the following routines, since they
  88.  * depend on /etc/passwd.  In the context where the routines are used,
  89.  * we don't need them anyway.
  90.  */
  91. #define getgid() -1
  92. #define getuid() -1
  93. #define geteuid() -1
  94. #endif
  95.  
  96. /* External Kermit Variables, see ckmain.c for description. */
  97.  
  98. extern int size, rpsiz, urpsiz, speed, local, 
  99.   server, displa, binary, parity, deblog, escape, xargc, flow,
  100.   turn, duplex, nfils, ckxech, pktlog, seslog, tralog, stdouf,
  101.   turnch, dfloc, keep, maxrps, warn, quiet, cnflg, tlevel;
  102.  
  103. extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;
  104. extern char *dialv, *loginv;
  105. extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist;
  106. extern char *DIRCMD, *PWDCMD, cmerrp[];
  107. extern CHAR sstate, ttname[];
  108. char *strcpy(), *getenv();
  109. #ifdef AMIGA
  110. char *getcwd();
  111. #endif
  112.  
  113. /* Declarations from cmd package */
  114.  
  115. extern char cmdbuf[];            /* Command buffer */
  116.  
  117. /* Declarations from ck?fio.c module */
  118.  
  119. extern char *SPACMD, *zhome();        /* Space command, home directory. */
  120. extern int backgrd;            /* Kermit executing in background */
  121.  
  122. /* The background flag is set by ckutio.c (via conint() ) to note whether */
  123. /* this kermit is executing in background ('&' on shell command line).    */
  124.  
  125.  
  126. /* Variables and symbols local to this module */
  127.  
  128. char line[CMDBL+10], *lp;        /* Character buffer for anything */
  129. char debfil[50];            /* Debugging log file name */
  130. char pktfil[50];            /* Packet log file name */
  131. char sesfil[50];            /* Session log file name */
  132. char trafil[50];            /* Transaction log file name */
  133.  
  134. int n,                    /* General purpose int */
  135.     cflg,                /* Command-line connect cmd given */
  136.     action,                /* Action selected on command line*/
  137.     repars,                /* Reparse needed */
  138.     cwdf = 0;                /* CWD has been done */
  139.  
  140. #define MAXTAKE 20            /* Maximum nesting of TAKE files */
  141. FILE *tfile[MAXTAKE];            /* File pointers for TAKE command */
  142.  
  143. char *homdir;                /* Pointer to home directory string */
  144. char cmdstr[100];            /* Place to build generic command */
  145.  
  146. /*  C M D L I N  --  Get arguments from command line  */
  147. /*
  148.  Simple Unix-style command line parser, conforming with 'A Proposed Command
  149.  Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World, Vol.1,
  150.  No.3, 1984.
  151. */
  152. cmdlin() {
  153.     char x;                /* Local general-purpose int */
  154.     cmarg = "";                /* Initialize globals */
  155.     cmarg2 = "";
  156.     action = cflg = 0;
  157.  
  158.     while (--xargc > 0) {        /* Go through command line words */
  159.     xargv++;
  160.     debug(F111,"xargv",*xargv,xargc);
  161.         if (**xargv == '-') {        /* Got an option (begins with dash) */
  162.         x = *(*xargv+1);        /* Get the option letter */
  163.         x = doarg(x);        /* Go handle the option */
  164.         if (x < 0) doexit(BAD_EXIT);
  165.         } else {            /* No dash where expected */
  166.         usage();
  167.         doexit(BAD_EXIT);
  168.     }
  169.     }
  170.     debug(F101,"action","",action);
  171.     if (!local) {
  172.     if ((action == 'g') || (action == 'r') ||
  173.         (action == 'c') || (cflg != 0))
  174.         fatal("-l and -b required");
  175.     }
  176.     if (*cmarg2 != 0) {
  177.     if ((action != 's') && (action != 'r') &&
  178.         (action != 'v'))
  179.         fatal("-a without -s, -r, or -g");
  180.     }
  181.     if ((action == 'v') && (stdouf) && (!local)) {
  182.         if (isatty(1))
  183.         fatal("unredirected -k can only be used in local mode");
  184.     }
  185.     if ((action == 's') || (action == 'v') ||
  186.         (action == 'r') || (action == 'x')) {
  187.     if (local) displa = 1;
  188.     if (stdouf) { displa = 0; quiet = 1; }
  189.     }
  190.  
  191.     if (quiet) displa = 0;        /* No display if quiet requested */
  192.  
  193.     if (cflg) {
  194.     conect();            /* Connect if requested */
  195.     if (action == 0) {
  196.         if (cnflg) conect();    /* And again if requested */
  197.         doexit(GOOD_EXIT);        /* Then exit indicating success */
  198.     }
  199.     }
  200.     if (displa) concb(escape);        /* (for console "interrupts") */
  201.     return(action);            /* Then do any requested protocol */
  202. }
  203.  
  204. /*  D O A R G  --  Do a command-line argument.  */
  205.  
  206. doarg(x) char x; {
  207.     int z; char *xp;
  208.  
  209.     xp = *xargv+1;            /* Pointer for bundled args */
  210.     while (x) {
  211.     switch (x) {
  212.  
  213. case 'x':                /* server */
  214.     if (action) fatal("conflicting actions");
  215.     action = 'x';
  216.     break;
  217.  
  218. case 'f':
  219.     if (action) fatal("conflicting actions");
  220.     action = setgen('F',"","","");
  221.     break;
  222.  
  223. case 'r':                /* receive */
  224.     if (action) fatal("conflicting actions");
  225.     action = 'v';
  226.     break;
  227.  
  228. case 'k':                /* receive to stdout */
  229.     if (action) fatal("conflicting actions");
  230.     stdouf = 1;
  231.     action = 'v';
  232.     break;
  233.  
  234. case 's':                 /* send */
  235.     if (action) fatal("conflicting actions");
  236.     if (*(xp+1)) fatal("invalid argument bundling after -s");
  237.     z = nfils = 0;            /* Initialize file counter, flag */
  238.     cmlist = xargv+1;            /* Remember this pointer */
  239.     while (--xargc > 0) {        /* Traverse the